#include<iostream>

using namespace std;
const int maxn = 1000;
int v[maxn];

int main() {
    int n, m;
    int maxv, minv;
    int left, right, mid, cunt, ptr, leave;
    while (scanf("%d%d", &n, &m) != EOF) {
        maxv = minv = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", v + i);
            maxv += v[i];
            if ( v[i] > minv ) {
                minv = v[i];
            }
        }
        left = minv, right = maxv;
        while (left < right) {
            mid = (left + right) / 2;
            cunt = 0;
            leave = 0;
            for (ptr = 0; ptr < n && cunt <= m; ptr++) {
                if ( leave >= v[ptr] ) {
                    leave -= v[ptr];
                } else {
                    leave = mid - v[ptr];
                    cunt++;
                }
            }
            if ( cunt <= m )
                right = mid;
            else
                left = mid + 1;
        }
        printf("%d\n", left);
    }

    return 0;
}